package com.sky.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.realogic.btp.sequence.KSequenceGenerator;
import org.realogic.cfm.domain.KPageResult;
import org.realogic.cfm.persistence.query.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.sky.demo.entity.EntityType;
import com.sky.demo.repository.EntityTypeDao;
import com.sky.demo.service.EntityTypeService;

/**
 * @see EntityTypeService
 */
@Service("entityTypeService")
public class EntityTypeServiceImpl implements EntityTypeService {

	// private Log log = LogFactory.getLog(getClass());

	private EntityTypeDao entityTypeDao;

	public EntityTypeServiceImpl() {

	}

	public EntityTypeDao getEntityTypeDao() {
		return entityTypeDao;
	}

	@Autowired
	public void setEntityTypeDao(EntityTypeDao entityTypeDao) {
		this.entityTypeDao = entityTypeDao;
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int create(final EntityType aModel) {
		if (aModel.getId() == null || aModel.getId() == 0l) {
			aModel.setId(KSequenceGenerator.uuidOfLang());
		}
		return entityTypeDao.create(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int update(final EntityType aModel) {
		return entityTypeDao.update(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int remove(final Long aKey) {
		return entityTypeDao.remove(aKey);
	}

	public EntityType read(final Long aKey) {
		return entityTypeDao.read(aKey);
	}

	public KPageResult query(QueryCondition aCondition) {
		List<EntityType> tmpList = entityTypeDao.query(aCondition);
		KPageResult temp = null;
		if (tmpList != null) {
			temp = new KPageResult(tmpList, aCondition.getTotalSize(), aCondition.getPageNo(), aCondition.getPageSize());
		}
		return temp;
	}

	public PageInfo<EntityType> query(Map<String, Object> aCondition, int aPageNo, int aPageSize) {
		return entityTypeDao.query(aCondition, aPageNo, aPageSize);
	}

	public List<EntityType> query(Map<String, Object> aCondition) {
		return entityTypeDao.query(aCondition);
	}

}